package com.xjrh.travel.data.apply.config.thread;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程执行类
 *
 * @author snps
 * @create 2025-10-30 22:58
 * @describe
 **/
@Configuration("dataApplyThreadPoolExecute")
public class ThreadPoolTaskExecutor {

    @Resource
    private ThreadPoolConfig dataApplyThreadPoolConfig;


    @Bean("asyncTaskExecutor")
    public org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor asyncTaskExecutor() {
        org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor executor = new org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor();
        executor.setCorePoolSize(dataApplyThreadPoolConfig.getCorePoolSize());
        executor.setMaxPoolSize(dataApplyThreadPoolConfig.getMaxPoolSize());
        executor.setKeepAliveSeconds(dataApplyThreadPoolConfig.getKeepAliveSeconds());
        executor.setQueueCapacity(dataApplyThreadPoolConfig.getQueueCapacity());
        executor.setThreadNamePrefix("DataApplyServiceExecutePool-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.setWaitForTasksToCompleteOnShutdown(true);
        executor.initialize();
        return executor;
    }


}